package github.saw96x.loadbalance;

import github.saw96x.common.utils.CollectionUtil;
import github.saw96x.remoting.pojo.RpcRequest;

import java.util.List;

/**
 * @author Saw96x
 * @date 2022/3/18 12:04
 */
public abstract class AbstractLoadBalance implements LoadBalance {
  @Override
  public String selectServiceAddress(List<String> serviceAddresses, RpcRequest rpcRequest) {
    if (CollectionUtil.isEmpty(serviceAddresses)) {
      return null;
    }
    if (serviceAddresses.size() == 1) {
      return serviceAddresses.get(0);
    }
    return doSelect(serviceAddresses, rpcRequest);
  }

  protected abstract String doSelect(List<String> serviceAddresses, RpcRequest rpcRequest);

}
